import java.util.*;
import java.util.stream.Collectors;

/**
 * note：
 * <p>
 * author: Caozhitong
 **/
public class Main {

    public static void main(String[] args) {

        calcMaxSubArray(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4});
    }

    public static void calcMaxSubArray(int[] array) {

        int res = 0;
        int len = array.length;

        for (int i = 0; i < len; i++) {

            int temp = array[i];
            res = max(res, temp);

            for (int j = i + 1; j < len; j++) {
                temp += array[j];
                res = max(res, temp);
            }
        }
        System.out.println(res);

    }

    public static int max(int i, int j) {
        return i > j ? i : j;
    }

}
